package com.ybu.oodd.controller;

import com.ybu.oodd.pojo.*;
import com.ybu.oodd.service.JobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/job")
@Slf4j
public class JobController {

    @Autowired
    private JobService jobService;

    /*
    * 条件分页查询岗位
    * */
    @PostMapping("/jobs")
    public Result getJobs(@RequestBody QueryParams queryParams){
        log.info("条件分页查询岗位{}",queryParams);
        PageResult<Job> page = jobService.getJobs(queryParams);
        return Result.success("获取成功",page);
    }

    /*
     * 根据userId和jobId更新statusId
     * */
    @PutMapping("/status")
    public Result updateStatus(@RequestBody Status status){
        log.info("更新状态{}",status);
        boolean a = jobService.updateStatus(status);
        if (a)
            return Result.success("更新成功");
        return Result.error("更新失败");
    }

    /*
     * 查询公司类型
     * */
    @GetMapping("/companyType")
    public Result getCompanyType(){
        log.info("查询公司类型");
        List<Map<Integer,String>> list = jobService.getCompanyType();
        return Result.success("查询公司类型成功",list);
    }

    /*
     * 查询校招招聘类型
     * */
    @GetMapping("/school/jobType")
    public Result getSchoolJobType(){
        log.info("查询校招招聘类型");
        List<Map<Integer,String>> list = jobService.getSchoolJobType();
        return Result.success("查询校招招聘类型成功",list);
    }

    /*
     * 查询实习招聘类型
     * */
    @GetMapping("/intern/jobType")
    public Result getInternJobType(){
        log.info("查询实习招聘类型");
        List<Map<Integer,String>> list = jobService.getInternJobType();
        return Result.success("查询实习招聘类型成功",list);
    }

    /*
     * 查询所有招聘类型
     * */
    @GetMapping("/jobType")
    public Result getJobType(){
        log.info("查询所有招聘类型");
        List<Map<Integer,String>> list = jobService.getJobType();
        return Result.success("查询所有招聘类型成功",list);
    }

    /*
     * 查询招聘招聘对象
     * */
    @GetMapping("/candidate")
    public Result getCandidateType(){
        log.info("查询招聘招聘对象");
        List<Map<Integer,String>> list = jobService.getCandidateType();
        return Result.success("查询招聘招聘对象成功",list);
    }

    /*
     * 查询学历
     * */
    @GetMapping("/educationalBackground")
    public Result getEducationalBackgroundType(){
        log.info("查询学历");
        List<Map<Integer,String>> list = jobService.getEducationalBackgroundType();
        return Result.success("查询学历成功",list);
    }

    /*
     * 查询投递状态类型
     * */
    @GetMapping("/status")
    public Result getStatusType(){
        log.info("查询投递状态类型");
        List<Map<Integer,String>> list = jobService.getStatusType();
        return Result.success("查询投递状态类型成功",list);
    }
}
